package com.wty.cmims.controller;

import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.MedicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/medication")
@Tag(name = "药品信息", description = "社区医疗信息后台管理系统api接口")
public class MedicationController {
    @Autowired
    private MedicationService medicationService;

    // 药品信息获取
    @PostMapping("/find")
    @Operation(summary = "药品信息获取", description = "药品信息获取")
    @Parameter(name = "medication",description = "药品信息")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Map<String, Object>> medicationFind(@RequestBody Map<String,Object> paramsMap){
        return medicationService.medicationFind(paramsMap);
    }

    // 添加药品信息
    @PostMapping("/add")
    @Operation(summary = "添加药品信息", description = "添加药品信息")
    @Parameter(name = "paramsMap",description = "参数列表")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> medicationAdd(@RequestBody Map<String,Object> paramsMap){
        return medicationService.medicationAdd(paramsMap);
    }

    @PutMapping("/update")
    @Operation(summary = "修改药品信息", description = "修改药品信息")
    @Parameter(name = "paramsMap",description = "参数列表")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> medicationUpdate(@RequestBody Map<String,Object> paramsMap){
        return medicationService.medicationUpdate(paramsMap);
    }

    @PutMapping("/delete")
    @Operation(summary = "删除药品信息", description = "删除药品信息")
    @Parameter(name = "id",description = "药品ID")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Void> medicationDelete(@RequestParam(name = "id") Integer medicationId){
        return medicationService.medicationDelete(medicationId);
    }

    // 已有药品下拉框
    @PostMapping("/findMedicationDropDown/{institutionId}")
    @Operation(summary = "药品下拉框", description = "药品下拉框")
    @Parameter(name = "medication",description = "药品信息")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Map<String, Object>> medicationDropDownFind(@PathVariable("institutionId") Integer institutionId){
        return medicationService.medicationDropDownFind(institutionId);
    }

    // 未有药品下拉框
    @PostMapping("/findMedicationDropDownWithout/{institutionId}")
    @Operation(summary = "药品下拉框", description = "药品下拉框")
    @Parameter(name = "medication",description = "药品信息")
    @ApiResponse(description = "处理结果",content = {
            @Content(
                    mediaType="application/json",
                    schema= @Schema(implementation = ResponseResult.class)
            )
    })
    public ResponseResult<Map<String, Object>> medicationDropDownWithoutFind(@PathVariable("institutionId") Integer institutionId){
        return medicationService.medicationDropDownWithoutFind(institutionId);
    }
}